import {request} from "../../util/request.js";
import dialog from "../../util/dialog";
export default {
    template:`        
            <div class="plugin-box plugin-auto row col-xs-9">
                <div class="open-select form-group">
                    <label>是否开启插件</label><br />
                    <select class="form-control" v-model.number="open">
                        <option value="1">开启</option>
                        <option value="0">关闭</option>
                    </select>
                </div>

                <div class="form-group">
                    <label>关注公众号粉丝每日自动赠送{{currency_name}}，设置1=每日赠送1{{currency_name}}，1,10=每日随机赠送1到10{{currency_name}}(半角逗号分隔)</label>
                    <input type="text" class="form-control" v-model="add" placeholder="每日赠送积分" />
                </div>

                <div class="form-group">
                    <label>取消关注每日扣除{{currency_name}}，设置1=取关一天扣除1{{currency_name}}，1,10=取关一天扣除1到10{{currency_name}}(半角逗号分隔,0=不扣除{{currency_name}})</label>
                    <input type="text" class="form-control" v-model="sub" placeholder="每日赠送积分" />
                </div>
                
                <button type="button" class="btn btn-info" @click="submit">确认</button>
            </div>
            `,
    data(){
        return {
            // 积分自定义名称
            currency_name:"积分",
            open:0,
            add:"1",
            sub:"0"
        }
    },
    props:{
      api:{
          type:String
      }
    },
    computed:{
        data:function(){
            let data = {
                open:this.open,
                add:this.add,
                sub:this.sub
            }
            return data;
        }
    },
    created(){
        this.getSetting()
        this.getMainSetting()
    },
    methods:{
        // Run
        /**
         * 获取参数
         */
        getSetting(){
            request("setting/easyFind",{
                return:["open","add","sub"]
            },this.api)
                .then((res)=>{
                    if(res.data.status === "success"){
                        let data = res.data.data;
                        this.open = data.open;
                        this.add = data.add;
                        this.sub = data.sub;
                    }
                })
        },
        /**
         * 获取主模块指定参数
         */
        getMainSetting(){
            request("setting/easyFind",{
                return:["currency_name"]
            })
                .then((res)=>{
                    if(res.data.status === "success"){
                        this.currency_name = res.data.data.currency_name;
                    }
                })
        },
        // Handel
        /**
         * 设置参数
         */
        submit(){
            request("setting/set",{
                data:this.data
            },this.api)
                .then((res)=>{
                    if(res.data.status === "success"){
                        dialog.alert(this,"设置成功");
                    }else{
                        dialog.alert(this,"设置失败");
                    }
                })
        }
    }
}